home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 13.5 KB | 476 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: MovieFra.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Lonnie Millett
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef MOVIEFRA_H
- #include "MovieFra.h"
- #endif
-
- #ifndef MOVIEFAC_H
- #include "MovieFac.h"
- #endif
-
- #ifndef MOVIEPAR_H
- #include "MoviePar.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWMEMMGR_H
- #include <FWMemMgr.h>
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- // ----- OpenDoc Includes -----
- #ifndef _FRAME_
- #include <Frame.h>
- #endif
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _MENUBAR_
- #include <MenuBar.h>
- #endif
-
- #ifndef _XMPSESSM_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _INFO_
- #include <Info.h>
- #endif
-
- #ifndef _ARBITRAT_
- #include <Arbitrat.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef _STDTYPES_
- #include <StdTypes.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
- #include <Quickdraw.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- #pragma segment MoviePart
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- const XMPID kCMovieFrameID = 'movi';
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::CMovieFrame
- //----------------------------------------------------------------------------------------
- CMovieFrame::CMovieFrame()
- : FW_CFrame()
- {
- fMoviePart = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::~CMovieFrame
- //----------------------------------------------------------------------------------------
- CMovieFrame::~CMovieFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::InitMovieFrame
- //----------------------------------------------------------------------------------------
- void CMovieFrame::InitMovieFrame(XMPFrame* xmpFrame, CMoviePart* moviePart)
- {
- this->InitFrame(xmpFrame, moviePart);
-
- fMoviePart = moviePart;
-
- AddToFocusSet(fMoviePart->GetKeyFocusToken());
- AddToFocusSet(fMoviePart->GetMenuFocusToken());
- AddToFocusSet(fMoviePart->GetSelectionFocusToken());
-
- this->SetDroppable(TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::NewFacet
- //----------------------------------------------------------------------------------------
- FW_CFacet* CMovieFrame::NewFacet(XMPFacet* xmpFacet)
- {
- CMovieFacet* facet = new CMovieFacet;
- facet->InitMovieFacet(xmpFacet, this);
-
- return facet;
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::FacetAdded
- //----------------------------------------------------------------------------------------
- void CMovieFrame::FacetAdded(FW_CFacet* facet)
- {
- FW_CFrame::FacetAdded(facet);
-
- Movie newMovie;
-
- // Determine from where we should get our movie
-
- // Get any existing movie and use it since all movies are supposed to be in-synch
- Movie currentMovie = ((CMovieFacet*)fMoviePart->GetAnyExistingFacet())->GetMovie();
- if (currentMovie)
- {
- FW_Boolean dataRefChanged;
- FW_PlatformHandle movieHandle = FW_CMemoryManager::AllocateSystemHandle(0);
- THROW_IF_NULL(movieHandle);
-
- THROW_IF_ERROR(::PutMovieIntoHandle(currentMovie, movieHandle));
- THROW_IF_ERROR(::NewMovieFromHandle(&newMovie, movieHandle, newMovieActive, &dataRefChanged));
-
- FW_CMemoryManager::FreeSystemHandle(movieHandle);
- }
- // Otherwise look at the part to see if we have internalized a movie from storage
- else if (fMoviePart->GetMovieHandle())
- {
- newMovie = fMoviePart->GetNewMovieFromMovieHandle();
- }
- // Looks like we're just starting out
- else
- newMovie = NULL;
-
- ((CMovieFacet*)facet)->SetMovie(newMovie);
- ((CMovieFacet*)facet)->SetMovieLooping(fMoviePart->GetMovieLooping());
-
- FW_CRect movieBox;
-
- if (this->IsRoot())
- this->GetFrameShapeBounds(&movieBox);
- else
- ((CMovieFacet*)facet)->GetMovieBoundingBox(&movieBox);
-
- this->AdjustFrameSize(movieBox);
-
- if (this->IsRoot())
- {
- ((CMovieFacet*)facet)->AdjustMovieBox();
- ((CMovieFacet*)facet)->DoMovieSetVisible(TRUE);
- }
-
- this->UpdateUsedAndActiveShapes();
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::CreateChildWindow
- //----------------------------------------------------------------------------------------
- XMPWindow* CMovieFrame::CreateChildWindow(XMPISOStr windowTitle)
- {
- FW_CRect windRect;
- CMovieFacet* movieFacet = (CMovieFacet*)this->GetActiveFacet();
- movieFacet->GetMovieBoundingBox(&windRect);
- windRect.Offset(ff(100), ff(100));
-
- return GetPart()->CreateXMPWindow(this,
- GetPart()->GetSession()->Tokenize(kXMPViewAsFrame),
- GetPresentation(),
- windowTitle,
- windRect,
- TRUE, // close box
- FALSE, // resizable
- FALSE, // floating
- TRUE, // should save
- zoomNoGrow);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
- void CMovieFrame::FrameShapeChanged()
- {
- this->UpdateUsedAndActiveShapes();
-
- FW_CFrameFacetIterator facets(this);
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->AdjustMovieBox();
- facets.Next();
- }
-
- XMPShape oldShape;
- this->GetFrameShape(&oldShape);
- this->Invalidate(&oldShape);
- this->GetXMPFrame()->InvalidateActiveBorder();
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::FocusStateChanged
- //----------------------------------------------------------------------------------------
- void CMovieFrame::FocusStateChanged(XMPTypeToken focus, FW_Boolean newState)
- {
- FW_CFrame::FocusStateChanged(focus, newState);
-
- if (focus == this->GetPart()->GetSelectionFocusToken() && !this->IsRoot())
- {
- FW_CRect movieBox;
- ((CMovieFacet*)this->GetActiveFacet())->GetMovieBoundingBox(&movieBox);
- this->AdjustFrameSize(movieBox);
- ((CMovieFacet*)this->GetActiveFacet())->ClipShapeChanged();
- ((CMovieFacet*)this->GetActiveFacet())->DoMovieSetVisible(newState);
- }
- }
-
- //------------------------------------------------------------------------------
- // CMovieFrame::HandleKeyDown
- //------------------------------------------------------------------------------
- FW_Boolean CMovieFrame::HandleKeyDown(XMPEventData event)
- {
- return ((CMovieFacet*)this->GetActiveFacet())->DoMovieKey(event);
- }
-
- //------------------------------------------------------------------------------
- // CMovieFrame::DoMenuEvent
- //------------------------------------------------------------------------------
- FW_Boolean CMovieFrame::DoMenuEvent(XMPMenuBar *menuBar, XMPCommandID commandID)
- {
- FW_Boolean menuHandled = FALSE;
- FW_CFrameFacetIterator facets(this);
- CMovieFacet* movieFacet;
-
- switch (commandID)
- {
- case cStartMovie:
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->StartMovie();
- facets.Next();
- }
-
- menuHandled = TRUE;
- break;
-
- case cStopMovie:
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->StopMovie();
- facets.Next();
- }
-
- menuHandled = TRUE;
- break;
-
- default:
- menuHandled = FW_CFrame::DoMenuEvent(menuBar, commandID);
- }
-
- return menuHandled;
- }
-
- //------------------------------------------------------------------------------
- // CMovieFrame::DoAdjustMenus
- //------------------------------------------------------------------------------
- void CMovieFrame::DoAdjustMenus(XMPMenuBar* menuBar)
- {
- FW_CFrame::DoAdjustMenus(menuBar);
-
- if (((CMovieFacet*)this->GetActiveFacet())->GetMovie())
- {
- menuBar->EnableCommand(cStartMovie, TRUE);
- menuBar->EnableCommand(cStopMovie, TRUE);
- }
- else
- {
- menuBar->EnableCommand(cStartMovie, FALSE);
- menuBar->EnableCommand(cStopMovie, FALSE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::AdjustFrameSize
- //----------------------------------------------------------------------------------------
- void CMovieFrame::AdjustFrameSize(const FW_CRect& movieBox)
- {
- XMPShape* newFrameShape = ::NewXMPShape(movieBox);
-
- this->RequestFrameShape(newFrameShape);
- this->UpdateUsedAndActiveShapes();
-
- XMPShape oldShape;
- this->GetFrameShape(&oldShape);
- this->Invalidate(&oldShape);
- this->GetXMPFrame()->InvalidateActiveBorder();
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::UpdateMovie
- //----------------------------------------------------------------------------------------
- void CMovieFrame::UpdateMovie()
- {
- FW_CFrameFacetIterator facets(this);
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->DoMovieIdle();
- facets.Next();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::SetNewMovie
- //----------------------------------------------------------------------------------------
- void CMovieFrame::SetNewMovie(Movie newMovie)
- {
- FW_CRect movieBox;
- FW_CFrameFacetIterator facets(this);
- CMovieFacet* movieFacet = (CMovieFacet*)facets.CurrentItem();
-
- // First the first facet just use the movie we were passed
- movieFacet->SetMovie(newMovie);
- movieFacet->GetMovieBoundingBox(&movieBox);
- this->AdjustFrameSize(movieBox);
-
- if (this->IsRoot())
- {
- FW_SPlatformRect windowRect;
- XMPPlatformWindow platformWindow;
-
- movieBox.AsPlatformRect(windowRect);
- // AMB - It may be a bad assumption that there is an active facet at this point.
- platformWindow = this->GetActiveFacet()->GetXMPWindow()->GetPlatformWindow();
- SizeWindow((WindowPtr)platformWindow, windowRect.right, windowRect.bottom, TRUE);
- this->GetActiveFacet()->GetXMPWindow()->Resized();
- }
-
- if (this->IsActive() || this->IsRoot())
- movieFacet->DoMovieSetVisible(TRUE);
-
- // If there are more facets then create a handle to clone movies from
- FW_PlatformHandle movieHandle = NULL;
- facets.Next();
- if (!facets.IsDone())
- {
- movieHandle = FW_CMemoryManager::AllocateSystemHandle(0);
- THROW_IF_NULL(movieHandle);
- THROW_IF_ERROR(::PutMovieIntoHandle(newMovie, movieHandle));
-
- while (!facets.IsDone())
- {
- movieFacet = (CMovieFacet*)facets.CurrentItem();
-
- FW_Boolean dataRefChanged;
- THROW_IF_ERROR(::NewMovieFromHandle(&newMovie, movieHandle, newMovieActive, &dataRefChanged));
- movieFacet->SetMovie(newMovie);
-
- if (this->IsActive() || this->IsRoot())
- movieFacet->DoMovieSetVisible(TRUE);
-
- facets.Next();
- }
- }
-
- if (movieHandle)
- FW_CMemoryManager::FreeSystemHandle(movieHandle);
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::CloseSelection
- //----------------------------------------------------------------------------------------
- void CMovieFrame::CloseSelection()
- {
- FW_CFrameFacetIterator facets(this);
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->CloseSelection();
- facets.Next();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::ClearSelection
- //----------------------------------------------------------------------------------------
- void CMovieFrame::ClearSelection(TimeValue currentTime, TimeValue duration)
- {
- FW_CFrameFacetIterator facets(this);
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->ClearSelection(currentTime, duration);
- facets.Next();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::SelectAll
- //----------------------------------------------------------------------------------------
- void CMovieFrame::SelectAll()
- {
- FW_CFrameFacetIterator facets(this);
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->SelectAll();
- facets.Next();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::PasteMovieToSelection
- //----------------------------------------------------------------------------------------
- void CMovieFrame::PasteMovieToSelection(Movie newMovie, TimeValue currentTime, TimeValue duration)
- {
- FW_CFrameFacetIterator facets(this);
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->PasteMovieToSelection(newMovie, currentTime, duration);
- facets.Next();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::PasteHandleToSelection
- //----------------------------------------------------------------------------------------
- void CMovieFrame::PasteHandleToSelection(FW_PlatformHandle newHandle, OSType handleType, TimeValue currentTime, TimeValue duration)
- {
- FW_CFrameFacetIterator facets(this);
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->PasteHandleToSelection(newHandle, handleType, currentTime, duration);
- facets.Next();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CMovieFrame::ToggleLooping
- //----------------------------------------------------------------------------------------
- void CMovieFrame::ToggleLooping(FW_Boolean looping)
- {
- FW_CFrameFacetIterator facets(this);
- while (!facets.IsDone())
- {
- ((CMovieFacet*)facets.CurrentItem())->SetMovieLooping(looping);
- facets.Next();
- }
- }
-